package Exception;


import java.util.Scanner;

public class Exception_homework {
    static String[] userName = {"李狗蛋","王狗蛋","李宇春"};

    public static void main(String[] args) throws RegisterException{
        System.out.println("请输入要注册的用户名");
        String sc = new Scanner(System.in).next();
        checkUserName(sc);
    }
    public static void checkUserName(String username) throws RegisterException{
        for(String name:userName)
        {
            if(name.equals(username)) {
                try
                {
                    throw new RegisterException("该用户名已被占用");
                }catch(RegisterException e)
                {
                    e.printStackTrace();
                    return;
                }
            }
        }
        System.out.println("恭喜你注册成功");
    }
}

